package main

import (
	"demo1/llm/doubao"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {

	r := gin.Default()
	group := r.Group("hxj-server")

	group.POST("/stream", stream) //流式请求

	err := r.Run(":8888")
	if err != nil {
		return
	}

}

func stream(c *gin.Context) {
	// 设置响应头
	c.Status(http.StatusOK)
	c.Writer.Header().Set("Content-Type", "text/event-stream")
	c.Writer.Header().Set("Cache-Control", "no-cache")
	c.Writer.Header().Set("Connection", "keep-alive")
	doubao.Dialog(c)
	c.Writer.Write([]byte("EOF"))
	c.Writer.Flush()
	// 模拟流式响应
	//for i := 0; i < 10; i++ {
	//	c.Writer.Write([]byte("data: " + string(i) + "\n\n"))
	//	time.Sleep(1 * time.Second)
	//}
}
